package com.lyp.qczp.service;

import java.util.HashMap;
//import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
//import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.lyp.qczp.dao.Profesdao;
import com.lyp.qczp.entity.Profes;
@Service
public class ProfesServiceImp implements ProfesService{
	@Autowired
	private Profesdao Profesdao;
	
	@Override
	public int save(Profes profes) {
		Profes save = Profesdao.save(profes);
		if (save!=null) {
			return 1;
		}
		return 0;
	}

	@Override
	public int deleteById(Integer pId) {
		Profesdao.deleteById(pId);
		return 1;
	}

	@Override
	public Map<String, Object> findAll(PageRequest pageable, Profes profes) {
		Page<Profes> findAll = Profesdao.findAll(pageable);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", findAll.getContent());
		map.put("total", findAll.getTotalElements());
		return map;
	}
	//条件查询Specification
			private Specification<Profes> selectquanpage(Profes Profes){
				return new Specification<Profes>() {

					/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					@Override
					public Predicate toPredicate(Root<Profes> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
						// TODO Auto-generated method stub
						Predicate conjunction = cb.conjunction();
					//	List<Expression<Boolean>> expressions = conjunction.getExpressions();
					//	if () {
					//		expressions.add(cb.equal(root.<Integer>get("jId"), jigou.getJId()));
					//	}
						
						
						return conjunction;
					}
				};
			}
}
